/**
 *
 */
package com.gxa.ssm251.service.impl;


import com.gxa.ssm251.exception.BusinessException;
import com.gxa.ssm251.mapper.UserMapper;
import com.gxa.ssm251.pojo.User;
import com.gxa.ssm251.service.UserService;
import com.gxa.ssm251.util.MD5Util;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author bilei
 * @date 2021年3月31日
 */
@Repository("userService")
public class UserServiceImpl implements UserService {

    // UserDao对象解决具体的持久化操作
    @Resource
    private UserMapper userMapper = null;


    @Override
    public User selectByPhone(String phone) throws Exception {
        User user = userMapper.selectByPhone(phone);
        return user;
    }

    //这就是事务开启的注解
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public Integer register(User regiuser) throws Exception {
        Integer lines = userMapper.insert(regiuser);
        return lines;

    }


    @Override
    public User login(String name) throws Exception {

        /*List<User> users = userMapper.selectLikeName(name);
        if (users != null) {
			if (MD5Util.encode(pwd).equals(users.getPwd())) {
				return null;
			} else {
				throw new BusinessException("用户名或密码不正确");
			}
		} else {
			throw new BusinessException("不存在的用户");
		}*/
        return null;
    }

    @Override
    public Integer deleteById(Integer id) {
        Integer integer = userMapper.deleteById(id);
        return integer;
    }

    @Override
    public List<User> selectAllById(Integer id) {
        List<User> users = userMapper.selectAllById(id);
        return users;
    }

    @Override
    public Integer insert(User user) throws Exception {
        Integer insert = userMapper.insert(user);
        return insert;
    }

    @Override
    public Integer update(User user) {
        Integer update = userMapper.update(user);
        return update;
    }

    @Override
    public List<User> selectLikeNameOrPhone(String param) {
        List<User> users = userMapper.selectLikeNameOrPhone("%" + param + "%");
        return users;
    }

    @Override
    public List<User> exportUserInfo() {
        List<User> userList = userMapper.exportUserInfo();
        return userList;
    }

    @Override
    public List<User> selectByPage(Integer page, Integer size) {
        List<User> userList = userMapper.selectByPage((page-1)*size,size);
        return userList;
    }

    @Override
    public List selectAllBypage(Integer page, Integer size) throws Exception {
        return userMapper.selectAllBypage(page, size);
    }

    @Override
    public User selectById(Integer id) {
        User user = userMapper.selectById(id);
        return user;
    }
//
//	@Override
//	public List<UserBase> selectAlluser() throws Exception {
//		List<UserBase> a1= userDao.selectAll();
//
//		return a1;
//	}
//	@Override
//	public List<UserBase> selectAllByPage(Integer page, Integer size) throws Exception {
//		List<UserBase> userList = userDao.selectByPage(page, size);
//		return userList;
//	}
//
//	@Override
//	public Integer deleteById(Integer id) throws Exception {
//		Integer integer = userDao.deleteById(id);
//		return integer;
//	}
//
//	@Override
//	public void update(Integer id, UserBase user) throws Exception {
//		UserBase selectedUser = userDao.selectById(id);
//		if(selectedUser != null){
//			selectedUser.setName(user.getName());
//			selectedUser.setPwd(MD5Util.encode(user.getPwd()));
//		}
//		userDao.update(id,selectedUser);
//	}

}
